﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="/js/jquery-1.6.2.min.js" type="text/javascript"> </script>
    <script src="/js/bootstrap.min.js" type="text/javascript"> </script>
    <script src="/js/knockout-1.2.1.js" type="text/javascript"> </script>
    <script src="/js/dishdash.widgetconfiguration.js" type="text/javascript"> </script>
</head>
<body>
    <div class="navbar">
        <div class="navbar-inner">
            <div class="container">
                <a class="brand" href="#">Dish Dash</a>
                <ul class="nav">
                    <li class="active"><a href="#">Dashboard</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="span8">
        <button class="btn btn-primary" style="vertical-align: top" onclick=" addWidget(); ">
            Add Widget</button>
    </div>
    <div class="span8">
         <label class="control-label">List All Widgets</label>
         <button class="btn btn-primary" style="vertical-align: top" onclick=" loadWidgetsTest(); ">
                        Get All Widgets</button>
          <div class="controls">
                    <input id="txtWidgetList" type="text" class="input-xlarge" />
                </div>
                 <label class="control-label">Enter Name of Widget Below</label>
         <button class="btn btn-primary" style="vertical-align: top" onclick=" getAWidgetTest(); ">
                        Get A Widget</button>
          <div class="controls">
                    <input id="txtWidgetNameTest" type="text" class="input-xlarge" />
                </div>
                
         <button class="btn btn-primary" style="vertical-align: top" onclick=" dishdash.widgetconfiguration.clearStorage(); ">
                        Clear Local Store</button>

    </div>
    <div class="span8">
        
    </div>
    <div id="Add Widget" style="visibility: hidden">
        <form class="span8">
        <fieldset>
            <legend>Add Widget (will be hidden until Add Widget is Selected)</legend>
            <div class="control-group">
                <label class="control-label">
                    Name</label>
                <div class="controls">
                    <input id="Widget Name" type="text" class="input-xlarge" />
                </div>
            </div>
            
            <div class="control-group">
                <label class="control-label">
                    Precision</label>
                <div class="controls">
                    <input id="Precision" type="text" class="input-xlarge" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    Refresh Rate</label>
                <div class="controls">
                    <input id="Refresh Rate" type="text" class="input-xlarge" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    Sampling Period</label>
                <div class="controls">
                    <input type="text" class="input-xlarge" id="Sampling Period" />&nbsp;&nbsp;&nbsp;
                    <button class="btn btn-primary" style="vertical-align: top" onclick=" saveWidgetTest(); ">
                        Add Widget Test</button>
                </div>
            </div>
        </fieldset>
        </form>
    </div>
    <script type="text/javascript">

        addWidget = function() {

            var addWidgetDiv = document.getElementById("Add Widget");
            addWidgetDiv.style.visibility = "visible";
        };

//        saveAWidget = function (objWidget) {
//            try {
//                //If localStorage supports with the browser
//                if (localStorage) {

//                    //Get the existing widget list if there is one
//                    var objWidgets = localStorage.getItem("Widgets");

//                    if (objWidgets != 'null') {
//                        //Parse the list
//                        var arWidgets = JSON.parse(objWidgets);
//                    }
//                    else {
//                       //create array to store list
//                        var arWidgets = {};
//                    }
//                    //Set name of widget as the key
//                    arWidgets[objWidget.name] = objWidget;
//                    localStorage.setItem("Widgets", JSON.stringify(arWidgets));

//                }
//            }
//            catch (err) {
//                alert(err.Description);
//            }
//        };


//        getAWidget = function (widgetname) {
//            try {
//                //If localStorage supports with the browser
//                if (localStorage) {
//                    var sWidgets = localStorage.getItem("Widgets");

//                    var parsedResult = $.parseJSON(sWidgets);

//                    return parsedResult[widgetname];
//                }
//            }
//            catch (err) {
//                alert(err.Description);
//            }

//        };

//        getAllWidgets = function () {
//            try {
//                //If localStorage supports with the browser
//                if (localStorage) {
//                    var sWidgets = localStorage.getItem("Widgets");

//                    var parsedResult = $.parseJSON(sWidgets);

//                    return parsedResult;
//                }
//            }
//            catch (err) {
//                alert(err.Description);
//            }

//        };

        saveWidgetTest = function() {
            try {
                //If localStorage supports with the browser
                if (localStorage) {


                    var event1 = new Array();
                    event1.push("ProfilingApp.Handlers.SecurityHandler.CreateCustomerResponse");

                    var w = new dishdash.widgetconfiguration.Widget();

                    w.widgetName = document.getElementById("Widget Name").value;
                    w.events = event1;
                    w.samplePeriod = document.getElementById("Sampling Period").value;
                    w.precision = document.getElementById("Precision").value;
                    w.refreshPeriod = document.getElementById("Refresh Rate").value;
                    //alert(w);
                    dishdash.widgetconfiguration.saveAWidget(w);
                }
            } catch(err) {
                alert(err.Description);
            }
        };

        loadWidgetsTest = function() {
            try {

                var result = dishdash.widgetconfiguration.getAllWidgets();
                var list = "";
                $.each(result, function(keyname, objwidget) {
                    //display the key and value pair

//                        alert('object is -' + objwidget["name"]);
                    //alert('datapoint name is - ' + objwidget["dataPoints"]["name"]);
                    list = list + ' Name = ' + objwidget["widgetName"] + ' Sample Period= ' + objwidget["samplePeriod"] + ' ';
                });
                document.getElementById("txtWidgetList").value = list;
            } catch(err) {
                alert(err.Description);
            }
        };

        getAWidgetTest = function() {
            try {

                var w = dishdash.widgetconfiguration.getAWidget(document.getElementById("txtWidgetNameTest").value);
                alert("Name is " + w.widgetName);
                alert("Sampling Period is " + w.samplePeriod);
                alert('datapoint name is - ' + w.events[0]);

            } catch(err) {
                alert(err.Description);
            }
        };

        clearStorage = function() {
            if (localStorage) {
                localStorage.setItem("Widgets", null);
                alert("Cleared");
            }
        };

//        GraphingFunctions = {
//            Sum: "SUM",
//            Average: "AVERAGE",
//            Value: "VALUE"
//        }

//        DataPoints = function () {
//            this.name = "";
//            this.criteria = "";
//            this.graphingFunction = GraphingFunctions.Average;
//        };

//        Widget = function () {
//            this.name = "";
//            this.dataPoints = [];
//            this.samplePeriodInSeconds = 360;
//            this.precision = "";
//            this.refreshRate = "";
//        };


    </script>
</body>
</html>
